/*    */ package com.zimbra.cs.zimlet.handler;
/*    */ 
/*    */ import com.google.common.collect.Lists;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.zimlet.ZimletConf;
/*    */ import com.zimbra.cs.zimlet.ZimletException;
/*    */ import com.zimbra.cs.zimlet.ZimletHandler;
/*    */ import java.util.List;
/*    */ import java.util.regex.Matcher;
/*    */ import java.util.regex.Pattern;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class RegexHandler
/*    */   implements ZimletHandler
/*    */ {
/*    */   private Pattern mPattern;
/*    */   
/*    */   public String[] match(String text, ZimletConf config)
/*    */     throws ZimletException
/*    */   {
/* 43 */     if (this.mPattern == null) {
/* 44 */       String handlerConfig = config.getGlobalConf("ZIMLET_CONFIG_REGEX_VALUE");
/* 45 */       if (handlerConfig == null) {
/* 46 */         throw ZimletException.ZIMLET_HANDLER_ERROR("null regex value");
/*    */       }
/* 48 */       this.mPattern = Pattern.compile(handlerConfig);
/* 49 */       ZimbraLog.zimlet.debug("RegexHandler %s=%s (for config=%s)", new Object[] { "ZIMLET_CONFIG_REGEX_VALUE", handlerConfig, config.getClass().getName() });
/*    */     }
/*    */     
/* 52 */     Matcher m = this.mPattern.matcher(text);
/* 53 */     List<String> l = Lists.newArrayList();
/* 54 */     while (m.find()) {
/* 55 */       l.add(text.substring(m.start(), m.end()));
/* 56 */       ZimbraLog.zimlet.trace("RegexHandler matcher found match=[%s] for pattern=[%s]", new Object[] { text.substring(m.start(), m.end()), this.mPattern.pattern() });
/*    */     }
/*    */     
/* 59 */     return (String[])l.toArray(new String[0]);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/zimlet/handler/RegexHandler.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */